package thread;
/*
  守护线程
 */
public class DaemonThreadDemo {
    public static void main(String[] args) {
        Thread rose = new Thread("rose"){
            public void run(){
                for(int i = 0;i<5;i++){
                    System.out.println("let me go!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(getName()+"啊啊啊啊啊啊啊啊啊啊AAAAAAaaaaaaaaa....");
                System.out.println("扑通！");
            }
        };
        Thread jack = new Thread("jack"){
            public void run(){
                while(true){
                    System.out.println("U jump! I jump!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        rose.start();
        //设置守护线程必须在线程启动前进行，否则会抛出异常
        jack.setDaemon(true);
        jack.start();
    }
}
